package com.org.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.org.bean.common.DangerInfo;
import com.org.bean.common.DisasterInfo;
import com.org.bean.common.PlanInfo;
import com.org.bean.setting.DepartInfo;
import com.org.bean.setting.EquipmentInfo;
import com.org.bean.setting.MaterialsInfo;
import com.org.bean.setting.PersonInfo;
import com.org.bean.system.TunnelInfo;
import com.org.bean.system.UserInfo;
import com.org.service.DangerService;
import com.org.service.DepartService;
import com.org.service.DisasterService;
import com.org.service.EquipmentService;
import com.org.service.MaterialsService;
import com.org.service.PersonService;
import com.org.service.PlanService;
import com.org.service.TunnelService;
import com.org.service.UserService;
import com.org.uitl.ExportExcelUtils;

@Controller
public class ExportExcelAction {
	@Autowired
	private UserService userService;
	@Autowired
	private DisasterService disasterService;
	@Autowired
	private PlanService planService;
	@Autowired
	private EquipmentService equipmentService;
	@Autowired
	private MaterialsService materialsService;
	@Autowired
	private PersonService personService;
	@Autowired
	private DepartService departService;
	@Autowired
	private DangerService dangerService;
	@Autowired
	private TunnelService tunnelService;

	@RequestMapping("/exportUser")
	public void exportUser(HttpServletRequest request,
			HttpServletResponse response) {
		try { // 查询用户的所有信息
			List<UserInfo> userlist = userService.findAll();
			String title = "用户信息表";
			String[] rowsName = new String[] { "ID", "用户名", "密码", "是否为管理员",
					"上次登录", "联系方式", "备注" };
			List<Object[]> dataList = new ArrayList<Object[]>();
			Object[] objs = null;
			for (int i = 0; i < userlist.size(); i++) {
				UserInfo po = userlist.get(i);
				objs = new Object[rowsName.length];
				objs[0] = po.getUserId();
				objs[1] = po.getUserName();
				objs[2] = po.getPassword();
				objs[3] = po.getIsAdmin();
				objs[4] = po.getContact();
				objs[5] = po.getLastLogin();
				objs[6] = po.getRemark();
				dataList.add(objs);
			}
			ExportExcelUtils ex = new ExportExcelUtils(title, rowsName, // 调用导出exel的工具类
					dataList, response);
			ex.exportData();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/exportPlan")
	public void exportPlan(HttpServletRequest request,
			HttpServletResponse response) {
		try { // 查询应急预案的所有信息
			List<PlanInfo> planlist = planService.findAll();
			String title = "应急预案信息表";
			String[] rowsName = new String[] { "ID", "应急预案名", "类型", "负责人",
					"联系方式", "应急措施" };
			List<Object[]> dataList = new ArrayList<Object[]>();
			Object[] objs = null;
			for (int i = 0; i < planlist.size(); i++) {
				PlanInfo po = planlist.get(i);
				objs = new Object[rowsName.length];
				objs[0] = po.getEmerplanId();
				objs[1] = po.getEmerplanName();
				objs[2] = po.getType();
				objs[3] = po.getPersonInfo().getPersonName();
				objs[4] = po.getPersonInfo().getContact();
				objs[5] = po.getEmerMeasure();
				dataList.add(objs);
			}
			ExportExcelUtils ex = new ExportExcelUtils(title, rowsName, // 调用导出exel的工具类
					dataList, response);
			ex.exportData();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/exportDisaster")
	public void exportDisaster(HttpServletRequest request,
			HttpServletResponse response) {
		try { // 查询地质灾害的所有信息
			List<DisasterInfo> dsasterlist = disasterService.findAll();
			String title = "地质灾害信息表";
			String[] rowsName = new String[] { "ID", "地质灾害名", "经度", "纬度", "规模",
					"危险对象", "处理结果" };
			List<Object[]> dataList = new ArrayList<Object[]>();
			Object[] objs = null;
			for (int i = 0; i < dsasterlist.size(); i++) {
				DisasterInfo po = dsasterlist.get(i);
				objs = new Object[rowsName.length];
				objs[0] = po.getDisasterId();
				objs[1] = po.getDisasterName();
				objs[2] = po.getpLongitude();
				objs[3] = po.getpDimension();
				objs[4] = po.getScale();
				objs[5] = po.getDanger();
				objs[6] = po.getProposal();
				dataList.add(objs);
			}
			ExportExcelUtils ex = new ExportExcelUtils(title, rowsName, // 调用导出exel的工具类
					dataList, response);
			ex.exportData();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/exportEquipment")
	public void exportEquipment(HttpServletRequest request,
			HttpServletResponse response) {
		try { // 查询应急设备的所有信息
			List<EquipmentInfo> equipmentlist = equipmentService.findAll();
			String title = "应急设备信息表";
			String[] rowsName = new String[] { "ID", "设备名", "数量", "负责人",
					"联系方式", "投入时间", "使用期限", "保养计划" };
			List<Object[]> dataList = new ArrayList<Object[]>();
			Object[] objs = null;
			for (int i = 0; i < equipmentlist.size(); i++) {
				EquipmentInfo po = equipmentlist.get(i);
				objs = new Object[rowsName.length];
				objs[0] = po.getEquipmentId();
				objs[1] = po.getEquipmentName();
				objs[2] = po.getNumber();
				objs[3] = po.getPersonInfo().getPersonName();
				objs[4] = po.getPersonInfo().getContact();
				objs[5] = po.getInputTime();
				objs[6] = po.getUsePeriod();
				objs[7] = po.getMaintenancePlan();
				dataList.add(objs);
			}
			ExportExcelUtils ex = new ExportExcelUtils(title, rowsName, // 调用导出exel的工具类
					dataList, response);
			ex.exportData();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/exportMaterial")
	public void exportMaterial(HttpServletRequest request,
			HttpServletResponse response) {
		try { // 查询应急物资的所有信息
			List<MaterialsInfo> materiallist = materialsService.findAll();
			String title = "应急物资信息表";
			String[] rowsName = new String[] { "ID", "物资名", "数量", "负责人",
					"联系方式", "投入时间", "保质期" };
			List<Object[]> dataList = new ArrayList<Object[]>();
			Object[] objs = null;
			for (int i = 0; i < materiallist.size(); i++) {
				MaterialsInfo po = materiallist.get(i);
				objs = new Object[rowsName.length];
				objs[0] = po.getMaterialsId();
				objs[1] = po.getMaterialsName();
				objs[2] = po.getNumber();
				objs[3] = po.getPersonInfo().getPersonName();
				objs[4] = po.getPersonInfo().getContact();
				objs[5] = po.getInputTime();
				objs[6] = po.getUsePeriod();
				dataList.add(objs);
			}
			ExportExcelUtils ex = new ExportExcelUtils(title, rowsName, // 调用导出exel的工具类
					dataList, response);
			ex.exportData();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/exportPerson")
	public void exportPerson(HttpServletRequest request,
			HttpServletResponse response) {
		try { // 查询应急负责人的所有信息
			List<PersonInfo> personlist = personService.findAll();
			String title = "应急负责人信息表";
			String[] rowsName = new String[] { "ID", "姓名", "联系方式", "地址", "备注" };
			List<Object[]> dataList = new ArrayList<Object[]>();
			Object[] objs = null;
			for (int i = 0; i < personlist.size(); i++) {
				PersonInfo po = personlist.get(i);
				objs = new Object[rowsName.length];
				objs[0] = po.getPersonId();
				objs[1] = po.getPersonName();
				objs[2] = po.getContact();
				objs[3] = po.getAdRegion();
				objs[4] = po.getRemark();
				dataList.add(objs);
			}
			ExportExcelUtils ex = new ExportExcelUtils(title, rowsName, // 调用导出exel的工具类
					dataList, response);
			ex.exportData();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/exportDepart")
	public void exportDepart(HttpServletRequest request,
			HttpServletResponse response) {
		try { // 查询应急部门的所有信息
			List<DepartInfo> departlist = departService.findAll();
			String title = "应急部门信息表";
			String[] rowsName = new String[] { "ID", "部门名", "类型", "负责人",
					"联系方式", "备注" };
			List<Object[]> dataList = new ArrayList<Object[]>();
			Object[] objs = null;
			for (int i = 0; i < departlist.size(); i++) {
				DepartInfo po = departlist.get(i);
				objs = new Object[rowsName.length];
				objs[0] = po.getDepartId();
				objs[1] = po.getDepartName();
				objs[2] = po.getType();
				objs[3] = po.getPersonInfo().getPersonName();
				objs[4] = po.getPersonInfo().getContact();
				objs[5] = po.getRemark();
				dataList.add(objs);
			}
			ExportExcelUtils ex = new ExportExcelUtils(title, rowsName, // 调用导出exel的工具类
					dataList, response);
			ex.exportData();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/exportDanger")
	public void exportDanger(HttpServletRequest request,
			HttpServletResponse response) {
		try { // 查询险情记录的所有信息
			List<DangerInfo> dangertlist = dangerService.findAll();
			String title = "险情记录信息表";
			String[] rowsName = new String[] { "ID", "险情名", "描述", "经度", "纬度",
					"发生时间", "上报人", "联系方式", "处理结果" };
			List<Object[]> dataList = new ArrayList<Object[]>();
			Object[] objs = null;
			for (int i = 0; i < dangertlist.size(); i++) {
				DangerInfo po = dangertlist.get(i);
				objs = new Object[rowsName.length];
				objs[0] = po.getDangerId();
				objs[1] = po.getDangerName();
				objs[2] = po.getDescp();
				objs[3] = po.getDisasterInfo().getpLongitude();
				objs[4] = po.getDisasterInfo().getpDimension();
				objs[5] = po.getOccurrenceTime();
				objs[6] = po.getReportPerson();
				objs[7] = po.getContact();
				objs[8] = po.getTreatmentResult();
				dataList.add(objs);
			}
			ExportExcelUtils ex = new ExportExcelUtils(title, rowsName, // 调用导出exel的工具类
					dataList, response);
			ex.exportData();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@RequestMapping("/exportTunnel")
	public void exportTunnel(HttpServletRequest request,
			HttpServletResponse response) {
		try { // 查询隧道的所有信息
			List<TunnelInfo> tunnellist = tunnelService.findAll();
			String title = "隧道信息表";
			String[] rowsName = new String[] { "ID", "隧道名", "起始经度", "起始纬度",
					"终止经度", "终止纬度", "行政区域", "隧道长度", "车道数", "备注" };
			List<Object[]> dataList = new ArrayList<Object[]>();
			Object[] objs = null;
			for (int i = 0; i < tunnellist.size(); i++) {
				TunnelInfo po = tunnellist.get(i);
				objs = new Object[rowsName.length];
				objs[0] = po.getTunnelId();
				objs[1] = po.getTunnelName();
				objs[2] = po.getPfLongitude();
				objs[3] = po.getPfDimension();
				objs[4] = po.getPeLongitude();
				objs[5] = po.getPeDimension();
				objs[6] = po.getRegionInfo().getRegionName();
				objs[7] = po.getTunnelLength();
				objs[8] = po.getLaneNumber();
				objs[9] = po.getRemark();
				dataList.add(objs);
			}
			ExportExcelUtils ex = new ExportExcelUtils(title, rowsName, // 调用导出exel的工具类
					dataList, response);
			ex.exportData();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
